import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {DynamicFormDataService} from './dynamic-form-data.service';

@Component({
  selector: 'app-dynamic-form',
  templateUrl: './dynamic-form.component.html',
  styleUrls: ['./dynamic-form.component.css']
})
export class DynamicFormComponent implements OnInit {

  data: any[];

  constructor(private router: Router,
              private formDataService: DynamicFormDataService) {
  }

  ngOnInit(): void {
    const list = localStorage.getItem('dynamicFormList');
    if (list) {
      this.data = JSON.parse(list).map(item => JSON.parse(item));
    } else {
      this.data = [];
    }
  }

  editDynamicForm(data: any) {
    this.router.navigateByUrl('/dynamicForm/create');
    this.formDataService.setFormData(data);
  }
}
